var app = getApp();
Page({
  data: {
    username: null,
    password: null,
  },
  // onShow: function (options){
  //   var id = wx.getStorageSync('id');
  //   wx.navigateTo({ url: "../paster/paster" }); 
  // },
  onLoad: function (options) {
    // var that = this;
    // var id = wx.getStorageSync('id');
    // var username = wx.getStorageSync('username');
    // if (id !="" || id !=null){
    //   app.globalData.username = username;
    //   app.globalData.id = id;
    //   wx.navigateTo({ url: "../paster/paster" }) 
    // }

  },
  usernameInput: function (event) {
    this.setData({ username: event.detail.value })
  },
  passwordInput: function (event) {
    this.setData({ password: event.detail.value })
  },
  //登录
  loginBtnClick: function (e) {
    //获取用户名称和头像      
    //调用应用实例的方法获取全局数据
    var that = this;
    var phone = this.data.username;
    if (this.data.username == "" || this.data.username == null) {
      wx.showToast({
        title: '请输入账号名称',
        image: "../../images/error.png"
      });
      return false;
    }
    if (this.data.password == "" || this.data.password == null) {
      wx.showToast({
        title: '请输入密码',
        image: "../../images/error.png"
      });
      return false;
    }
    var data = {
      "type":"userlogin",
      "num": this.data.username,
      "password": this.data.password
    }
    wx.showLoading({
      title: "验证中...",
      mask: true
    });
    // wx.setEnableDebug({
    //   enableDebug: true
    // })
    app.func.reqForLogin(data, function (res) {
      console.info(res);
      if (res.code == "0") {
        console.info(res.message);
        wx.showToast({
          title: res.message
        })
      } else {
        wx.hideLoading();
        //登录成功存储staff
        app.globalData.username = res.vip_info.login_account;
        app.globalData.id = res.vip_info.id;
        //save logininfo
        wx.setStorageSync('username', res.vip_info.login_account);
        wx.setStorageSync('id', res.vip_info.id);
        wx.navigateTo({ url: "../paster/paster" })   
      }
    });
  },
})

